<template>
  <el-dialog draggable v-model="conf.visible" :title="opts.name" width="30%">
    <span
      >确认<span v-text="opts.Name"></span> :[<span v-text="form.Name"></span>]
      吗?</span
    >
    <template #footer>
      <span class="dialog-footer">
        <el-button @click="conf.visible = false">取消</el-button>
        <el-button type="primary" @click="save">确认</el-button>
      </span>
    </template>
  </el-dialog>
</template>

<script>
export default {
  data() {
    return {
      conf: {
        visible: false,
      },
      form: {},
      opts: {
        name: "删除",
      },
    };
  },
  methods: {
    show(opts, query) {
      this.conf.visible = true;
      this.form = query;
      this.opts = opts;
    },
    save() {
      let that = this;
      this.$theia.http
        .post(this.opts.URL, this.form)
        .then((res) => {
          that.conf.visible = false;
          that.$notify.success({
            title: "成功",
            message: that.opts.Name + "成功",
            duration: 5000,
          });
          that.$emit("onsaved");
        })
        .catch((err) => {
          that.conf.visible = false;
          let code = res.response.status;
          let msg = that.opts.Name + `失败(${code})`;
          that.$notify.error({ title: "失败", message: msg, duration: 5000 });
        });
    },
  },
};
</script>

<style>
</style>